package tzjz.example.task;

import tzjz.example.entity.CyryHistory;
import tzjz.example.service.ICyryHistoryService;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * @author renshuting
 * @date 2024/3/2 10:20
 */
public class CyHisThread implements Runnable{
    private List<CyryHistory> cyryHistories;
    private CountDownLatch begin;
    private CountDownLatch end;
    private ICyryHistoryService iCyryHistoryService;

    //创建个构造函数初始化 list,和其他用到的参数
    public CyHisThread(List<CyryHistory> list, CountDownLatch begin, CountDownLatch end,ICyryHistoryService iCyryHistoryService) {
        this.cyryHistories = list;
        this.begin = begin;
        this.end = end;
        this.iCyryHistoryService=iCyryHistoryService;
    }

    @Override
    public void run() {
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setLenient(false);
        List<CyryHistory> list =new ArrayList<>();
        iCyryHistoryService.saveOrUpdateBatch(list);
        try {
            begin.await();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            //计数器减一的
            end.countDown();
        }
    }
}
